/**
 * Created with CLion.
 * Description: 
 * User: loong
 * Date: 2021-03-19
 * Time: 8:29
 */
#ifndef CODSEEGMENT_ARROW_H
#define CODSEEGMENT_ARROW_H

#include <QtWidgets>
#include "DiagramBaseItem.h"

class Arrow
        : public QGraphicsPathItem
{
public:
    enum { Type = UserType + 2 };

    enum LineType{
        StraightLine = 0,
        RightAngleLine
    };
    enum ArrowStyle
    {
        Normal = 0,
        Triangle,
       /* TriangleFilled,
        Circle,
        CircleFilled,
        Diamond,
        DiamondFilled,
        Harpoon,
        HarpoonMirrored,
        Concave,
        ConcaveFilled,
        Reverse,
        XArrow*/
    };

    Arrow(DiagramBaseItem *startItem, DiagramBaseItem *endItem, LineType type, QGraphicsItem *parent = nullptr);

    ~Arrow() override = default;

    int type() const override
    { return Type; }

    QRectF boundingRect() const override;

    QPainterPath shape() const override;

    void setColor(const QColor &color)
    { color_ = color; }

    DiagramBaseItem *StartItem() const
    { return start_item_; }

    DiagramBaseItem *EndItem() const
    { return end_item_; }

    void UpdatePosition();

    ArrowStyle GetArrowStyle() const
    { return arrow_style_; }

    void SetArrowStyle(ArrowStyle arrowStyle)
    { arrow_style_ = arrowStyle; }

    const QString &getStartItemId() const
    { return start_item_id_; }

    const QString &getEndItemId() const
    { return end_item_id_; }

private:
    /**
     * @brief 为末端计算、绘制箭头
     * @param point
     */
    void CalculateArrow(QPointF point);
    /**
     * @brief 绘制直角连线
     */
    void DrawRightAngleLine();
    /**
     * @brief 绘制直线连线
     */
    void DrawStraightLine();
    /**
     * @brief 绘制曲线连线
     */
    void DrawCurveLine();
protected:
    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;

private:
    DiagramBaseItem *           start_item_;
    DiagramBaseItem *           end_item_;
    QString                     start_item_id_;
    QString                     end_item_id_;
    LineType                    line_type_;
    QColor                      color_;
    QPolygonF                   arrow_head_;
    ArrowStyle                  arrow_style_;
    QLineF                      line_;
};

#endif //CODSEEGMENT_ARROW_H
